Table of Contents [Hide/Show]
Code StructureAssign Values to VariablesThinking of Scripts Like a SpreadsheetLook Back FunctionsOffset ValuesPlotting FunctionsPlot Limit Lines, Center Lines and Range MarkersDisplay a Customized SummaryTick Value Conversions Converting Tick Values to Display Values Converting Tick Values to CASH and BackThe IF StatementThe NIL FieldGotcha 1: Don't Reassign VariablesGotcha 2: Don't Cause Circular ReferencesRecursion
sma
SMA
VSCALE_DECIMALS(2); periods = INPUT("MA Periods", 14, 1, 100); indcolor = INPUT("Color", Color.Blue); ma = SMA(CLOSE, periods); di = 100 * ((CLOSE - ma) / ma); PLOT_HISTOGRAM(di, 0.75, indcolor); SUMMARY("Disparity Index({?}) {?:F2}", periods, di);
VSCALE_DECIMALS(2);
periods
indcolor
ma
di
VSCALE_DECIMALS(2); periods = INPUT("MA Periods", 14, 1, 100); indcolor = INPUT("Color", Color.Blue); PLOT_HISTOGRAM(100 * ((CLOSE - SMA(CLOSE, periods)) / SMA(CLOSE, periods)), 0.75, indcolor); SUMMARY("Disparity Index({?}) {?:F2}", periods, 100 * ((CLOSE - SMA(CLOSE, periods)) / SMA(CLOSE, periods)));
x = (OPEN + HIGH + CLOSE) / 3
x
=(B2+C2+E2)/3
SUM
x = SUM(CLOSE, 3) / 3
CLOSE[-1]
rocclose = (CLOSE - CLOSE[-12]) / CLOSE[-12];
OFFSET
rocperiods = INPUT("ROC Periods", 12, 1, 1000); rocclose = (CLOSE - OFFSET(CLOSE, -1 * rocperiods) / OFFSET(CLOSE, -1 * rocperiods);
PLOT_LINE
PLOT_STEP
PLOT_BANDS
PLOT_WAVECREST
PLOT_POINTS
PLOT_HISTOGRAM
PLOT_CENTERLINE
PLOT_CENTERLINE(0);
PLOT_LIMITLINE
PLOT_LIMITLINE(0);
PLOT_RANGEMARKERS
PLOT_RANGEMARKERS(60, -60);
// Chande Momentum Oscillator // -------------------------- // A momentum oscillator developed by Tushar Chande. // CHART CONFIGURATION VSCALE_RANGE(-100, 100); // USER INPUT periods = INPUT("Periods", 14, 1, 100); ovrb = INPUT("Over-Bought Level", 50, 0, 100); ovrs = INPUT("Over-Sold Level", -50, -100, 0); linecolor = INPUT("Line Color", Color.Red); linethickness = INPUT("Line Thickness", 1, 1, 10); fillcolor = INPUT("Fill Color", Color.Pink); // CALCULATION cmo1 = SUM(IF(CLOSE > CLOSE[-1], CLOSE - CLOSE[-1], 0), periods); cmo2 = SUM(IF(CLOSE[-1] > CLOSE, CLOSE[-1] - CLOSE, 0), periods); cmo = 100 * ((cmo1 - cmo2) / (cmo1 + cmo2)); // PLOTTING AND SUMMARY PLOT_WAVECREST(cmo, 0, ovrb, ovrs, linethickness, linecolor, fillcolor); SUMMARY("CMO({?}) {?:F0}", periods, cmo);
SUMMARY
"CMO({?}) {?:F0}"
{?}
{?:F0}
F0
F3
F
smaval = SMA((OPEN + HIGH + CLOSE) / 3, 10); plot_line(smaval, 1, Color.Blue); SUMMARY("SMA(10) {?}", smaval);
smaval = SMA((OPEN + HIGH + CLOSE) / 3, 10); plot_line(smaval, 1, Color.Blue); SUMMARY("SMA(10) {?:F0}", smaval);
DISPLAY
smaval = SMA((OPEN + HIGH + CLOSE) / 3, 10); plot_line(smaval, 1, Color.Blue); SUMMARY("SMA(10) {?}", DISPLAY(smaval));
@
smaval = SMA((OPEN + HIGH + CLOSE) / 3, 10); plot_line(smaval, 1, Color.Blue); SUMMARY("SMA(10) {?}", @smaval);
CASH
$
CASHTICKS
IF
IF( < test condition >, < true part >, < false part > )
CLOSE > OPEN
// Make the number of periods configurable. mfperiods = INPUT("MFI Periods", 14, 1, 100); // Net money flow for this period. mf = TYP * V; // Aggregate the net money flow over the user-specified number of periods. posmf = SUM(IF(TYP > TYP[-1], mf, 0), mfperiods); negmf = SUM(IF(TYP < TYP[-1], mf, 0), mfperiods); // Compute the money flow index for this period, taking care not to divide by zero. mfi = IF( negmf = 0, IF(posmf = 0, 50, 100), 100 - 100 / (1 + posmf / negmf)); // Plot the money flow as a wavecrest centered at 50 with overbought and oversold levels at 80 and 20. PLOT_WAVECREST(mfi, 50, 70, 30, 1, Color.Brown, Color.Brown); SUMMARY("MFI({?}) {?:F2}", mfperiods, mfi);
IF(TYP > TYP-1, mf, 0)
IF(TYP < TYP-1, mf, 0)
mfi
negmf = 0
posmf = 0
PLOT_HISTOGRAM(VOLUME, 0.72, Color.Blue); SUMMARY("Volume {0:N0}", VOLUME);
PLOT_HISTOGRAM(VOLUME, 0.72, IF(CLOSE > OPEN, Color.Blue, Color.Green)); SUMMARY("Volume {0:N0}", VOLUME);
NIL
OPEN
HIGH
LOW
CLOSE
VOLUME
prvol = IF(BARPERCENT > 0.05, VOLUME / BARPERCENT, VOLUME[-1]); // Plot the pro-rated volume bar. PLOT_HISTOGRAM(IF(INDEX >= COUNT - 1, prvol, NIL), 0.9, COLOR.Yellow); // Plot the real volume. PLOT_HISTOGRAM(VOLUME, 0.7, IF(CLOSE >= OPEN, COLOR("#F08080"), COLOR("#696969"))); // Summary. SUMMARY("PRVOL: {?:F0} VOL: {?} ({?:F0}%)", IF(INDEX >= COUNT - 1, prvol, "-"), VOLUME, 100 * BARPERCENT);
BARPERCENT
INDEX
COUNT
xval = 10; xval = xval + 1;
xval = yval; yval = xval + 1;
xval
yval
xval = IF(INDEX = 0, 0, yval[-1]); yval = xval + 1;
yval = IF(INDEX = 0, 0, yval[-1] + 1);